package com.yehongyu.mytools.ui.applet;

import java.applet.Applet;
import java.awt.Button;
import java.awt.Choice;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class ChoiceApplet extends Applet implements ActionListener,ItemListener {

	/**序列ID*/
	private static final long serialVersionUID = 1L;

	private String[] description = { "Ebullient", "Obtuse", "Recalcitrant",
			"Brilliant", "Somnescent", "Timorous", "Florid", "Putrescent" };

	private TextField t = new TextField(30);

	private Choice c = new Choice();
	private Button b = new Button("Add items");

	int count = 0;

	public void init() {
		t.setEditable(false);
		for (int i = 0; i < 4; i++)
			c.addItem(description[count++]);
		add(t);
		add(c);
		add(b);
		c.addItemListener(this);
		b.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource().equals(b)){
			if (count < description.length)
				c.addItem(description[count++]);
		}else{
			System.out.println("Unknown Action！");
		}
	}

	@Override
	public void itemStateChanged(ItemEvent e) {
		if(e.getSource().equals(c)){
			t.setText("index: " + c.getSelectedIndex() + "   " + (String) c.getSelectedItem());
		}else{
			System.out.println("Unknown Action！");
		}
	}

}
